import request from '@/utils/request'

export default {
  getUserList(searchModel) {
    return request({
      url: '/user/list',
      method: 'get',
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        username: searchModel.username,
        phone: searchModel.phone
      }
    })
  },
  addUser(userForm) {
    return request({
      url: '/user/add',
      method: 'post',
      data: userForm
    })
  },
  getUserById(id) {
    return request({
      url: `/user/getUserById/${id}`,
      method: 'get'
    })
  },
  getUserProfile() {
    return request({
      url: `/user/profile`,
      method: 'get'
    })
  },
  updateUserProfile(user) {
    return request({
      url: `/user/profile`,
      method: 'put',
      data: user
    })
  },
  updateUserPwd(oldPassword, newPassword) {
    const data = {
      oldPassword,
      newPassword
    }
    return request({
      url: '/user/profile/updatePwd',
      method: 'put',
      params: data
    })
  },
  uploadAvatar(data) {
    return request({
      url: 'user/profile/avatar',
      method: 'post',
      data: data
    })
  },
  updateUser(userForm) {
    return request({
      url: '/user/update',
      method: 'post',
      data: userForm
    })
  },
  saveUser(UserForm) {
    if (UserForm.id == null || UserForm.id === undefined) {
      return this.addUser(UserForm);
    } else {
      return this.updateUser(UserForm);
    }
  },
  deleteUser(id) {
    return request({
      url: `/user/delete/${id}`,
      method: 'delete'
    })
  }
}
